

/*让文字和标签的大小随着屏幕的尺寸做变话 等比缩放*/
//(function () {
//var html = document.getElementsByTagName('html')[0];
    /*取到屏幕的宽度*/
//    var width = window.innerWidth;
    /* 640 100  320 50 */
//    var fontSize = 100/750*width;
    /*设置fontsize*/
//    html.style.fontSize = fontSize +'px';
//调整页面尺寸大小
//    window.onresize = function(){
//        var html = document.getElementsByTagName('html')[0];
        /*取到屏幕的宽度*/
//        var width = window.innerWidth;
        /* 640 100  320 50 */
//       var fontSize = 100/750 * width;
        /*设置fontsize*/
//       html.style.fontSize = fontSize +'px';
//    }
//})()

(function (doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
        };

    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
	
	var toast = function(opt)
	{
		this.opt = {
			title: opt.title || "提示",
			content: opt.content || undefined,
			icon: opt.icon || undefined,
			confirm: {
				text: opt.confirm && opt.confirm.text ? opt.confirm.text : "确定",
				callback: opt.confirm && opt.confirm.callback ? opt.confirm.callback : this.close,
			},
			cancel: {
				text: opt.cancel && opt.cancel.text ? opt.cancel.text : "取消",
				callback: opt.cancel && opt.cancel.callback ? opt.cancel.callback : this.close,
			},
		};
			
		if( "undefined" == typeof opt.cancel )
			this.opt.cancel = undefined;
		
		this.init();
	}
	
	toast.prototype = {
		init: function()
		{
// 			<div class="toast">
// 				<div class="main">
// 					<img class="icon" />
// 					<p class="title">提示</p>
// 					<p class="content">提示内容</p>
// 					<div class="btns">
// 						<button class="confirm">确定</button>
// 						<button class="cancel">取消</button>
// 					</div>
// 				</div>
// 			</div>
			this.close();
			this.toast_mask = doc.createElement("div");
			this.toast_mask.setAttribute("class","toast");
			
			var main = doc.createElement("div");
				main.setAttribute("class","main");
				
			if(this.opt.icon)
			{
				var icon = doc.createElement("img");
					icon.setAttribute("class","icon");
					icon.src = this.opt.icon;
					main.appendChild(icon);
			}
			
			var title = doc.createElement("p");
				title.setAttribute("class","title");
				title.innerHTML = this.opt.title;
				main.appendChild(title);
			
			if(this.opt.content)
			{
				var content = doc.createElement("p");
					content.setAttribute("class","content");
					content.innerHTML = this.opt.content;
					main.appendChild(content);
			}
			
			var btns = doc.createElement("div");
				btns.setAttribute("class","btns");
				
			
			if(this.opt.confirm)
			{
				var confirm = doc.createElement("button");
					confirm.setAttribute("class","confirm");
					confirm.innerHTML = this.opt.confirm.text;
					var _this = this;
					confirm.onclick = function()
					{
						if( _this.opt.confirm.callback && _this.opt.confirm.callback instanceof Function ) _this.opt.confirm.callback();
					}
					btns.appendChild(confirm);
			}
			
			if(this.opt.cancel)
			{
				var cancel = doc.createElement("button");
					cancel.setAttribute("class","cancel");
					cancel.innerHTML = this.opt.cancel.text;
					var _this = this;
					cancel.onclick = function()
					{
						if( _this.opt.cancel.callback && _this.opt.cancel.callback instanceof Function ) _this.opt.cancel.callback();
					}
					btns.appendChild(cancel);
			}
			
			main.appendChild(btns);
				
			this.toast_mask.appendChild(main);
			doc.getElementsByTagName("body")[0].appendChild(this.toast_mask);
		},
		close: function()
		{
			var items = doc.getElementsByClassName("toast");
			for (var i = 0; i< items.length; i++) 
			{
				items[i].remove();
			}
		}
	}
	win.toast = doc.toast = toast;
})(document, window);